package com.jsd2412.backend.patient.service.impl;

import com.jsd2412.backend.bed.mapper.BedMapper;
import com.jsd2412.backend.bed.pojo.vo.BedVO;
import com.jsd2412.backend.patient.mapper.PatientMapper;
import com.jsd2412.backend.patient.pojo.dto.PatientQuery;
import com.jsd2412.backend.patient.pojo.vo.PatientVO;
import com.jsd2412.backend.patient.service.PatientService;
import com.jsd2412.backend.room.mapper.RoomMapper;
import com.jsd2412.backend.room.pojo.vo.RoomVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientMapper patientMapper;
    @Autowired
    private RoomMapper roomMapper;
    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<PatientVO> selectPatient(PatientQuery patientQuery) {
        log.debug("查询老人业务:{}", patientQuery);
        List<PatientVO> list = patientMapper.selectPatient(patientQuery);
        //为每个patientVO填充房号,床号,楼层
        for (int i = 0; i < list.size(); i++) {
            PatientVO patientVO = list.get(i);
            RoomVO roomVO = roomMapper.selectById(patientVO.getRoomId());
            patientVO.setRoomNumber(roomVO.getNumber());
            patientVO.setFloorNumber(roomVO.getFloorNumber());
            BedVO bedVO = bedMapper.selectById(patientVO.getBedId());
            patientVO.setBedNumber(bedVO.getNumber());
        }
        return list;
    }

    @Override
    public List<PatientVO> selectNoBedPatient() {
        return patientMapper.selectNoBedPatient();
    }

    @Override
    public int patientTotal() {
        return patientMapper.patientTotal();
    }
}
